import { AnyAction } from 'redux';
import { LoginResponseData } from 'src/api/types';
import * as types from '../action-types';
export interface LoginState {
    isLoginState: boolean
    user?: LoginResponseData
    isLogin: boolean;
}

const initalState: LoginState = {
    isLoginState: true,
    isLogin: false
}

export default function loginReducer(state: LoginState = initalState, action: AnyAction): LoginState {
    switch (action.type) {
        case types.CHANGE_TRANSFORM: // 切换登录态
            return { ...state, isLoginState: !state.isLoginState };
        case types.SUCCESS_LOGIN: // 登录成功
            return { ...state, isLogin: true, user: action.payload }
        case types.LOGOUT: // 退出登录
            return { isLoginState: state.isLoginState, isLogin: false }
        default:
            return state;
    }
}